<!DOCTYPE html>
<html>
<head>
    <title>报表增加</title>
    {% include 'system/common/header.html' %}
</head>
<body>
<form class="layui-form" action="" lay-filter="myForm">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item">
                        <label class="layui-form-label">
                            新增报表
                        </label>
                        <button type="button" class="layui-btn layui-btn-normal" id="logo-img">选择文件</button>


                    </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">标识</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ type_code }}" readonly="readonly" name="typeCode"
                               lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="dataValue" lay-verify="title" autocomplete="off" placeholder="请输入值"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">默认</label>
                    <div class="layui-input-block">
                        <input type="radio" name="default" value="1" title="是">
                        <input type="radio" name="default" value="0" title="否" checked>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="enable" value="1" title="开启" checked>
                        <input type="radio" name="enable" value="0" title="关闭" >
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入描述" name="remark" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="dict-data-save" id="logo-upload-button">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>

            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'system/common/footer.html' %}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form
    let $ = layui.jquery
    var upload = layui.upload;
        //选完文件后不自动上传
        upload.render({
            elem: '#logo-img'
            , url: "{{ url_for('system.report.upload_api') }}"
            , auto: false
            , exts: 'docx|grf|pdf'
            , size: 1000
            , bindAction: '#logo-upload-button'
            , done: function (res) {

                if (res.success) {
                    // 获取表单其他数据
                      var formData = form.val('myForm');
                        {#alert(JSON.stringify(formData))#}
                      // 将文件上传结果和表单数据合并
                      var allData = Object.assign({}, formData, {fileInfo: res});

                      $.ajax({
                        url: '/system/report/dictData/save',
                        data: JSON.stringify(allData),
                        dataType: 'json',
                        contentType: 'application/json',
                        type: 'post',
                        success: function (result) {
                          if (result.success) {
                            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
                              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
                              parent.layui.table.reload('dict-data-table')
                            })
                          } else {
                            layer.msg(result.msg, { icon: 2, time: 1000 })
                          }
                        }
                      })
                      return false
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }
        });
    {#form.on('submit(dict-data-save)', function (data) {#}
    {#  $.ajax({#}
    {#    url: '/system/report/dictData/save',#}
    {#    data: JSON.stringify(data.field),#}
    {#    dataType: 'json',#}
    {#    contentType: 'application/json',#}
    {#    type: 'post',#}
    {#    success: function (result) {#}
    {#      if (result.success) {#}
    {#        layer.msg(result.msg, { icon: 1, time: 1000 }, function () {#}
    {#          parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页#}
    {#          parent.layui.table.reload('dict-data-table')#}
    {#        })#}
    {#      } else {#}
    {#        layer.msg(result.msg, { icon: 2, time: 1000 })#}
    {#      }#}
    {#    }#}
    {#  })#}
    {#  return false#}
    {#})#}
  })
</script>
<script>
</script>
</body>
</html>